/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alcatelparser.modules.io;

import alcatelparser.modules.ApplicationSettings;
import alcatelparser.modules.Env;
import alcatelparser.modules.I;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author geniuz
 */
public class FileNamer
{

    public FileNamer()
    {
        _fileSequenceNumber = 0L;
    }

    public final String generateFileName()
    {
        return "tmp.tmp";
        /*
        String s = (String)Env.getEnv().get(I.I(4882));
        if(s.indexOf(I.I(467)) != -1)
            s = returnFileName(s);
        String s1 = composeFileNamePart(s);
        String s2 = composeNumberPart();
        String s3 = getExtension();
        int i = s1.lastIndexOf(I.I(467));
        if(i != -1)
        {
            String s4 = s1.substring(i + 1);
            //if(!UIHelper.isInteger(s4) || I.I(4676).equals(getType()))
            {
                s3 = s4;
                s1 = s1.substring(0, i);
            }
        }
        return (new StringBuilder()).append(s1).append(s2).append(I.I(467)).append(s3).toString();
         * */
    }

    private String getExtension()
    {
        /*
        String s = ApplicationSettings.getInstance().getProperty(I.I(4612));
        FileNamePanel filenamepanel = (FileNamePanel)Env.getEnv().get(I.I(4653));
        if(I.I(4676).equals(s))
            return "";
        if(I.I(4681).equals(s))
            return filenamepanel.getLabelExtenstion();
        if(I.I(1339).equals(s))
            return filenamepanel.getDateTimeExtenstion();
        else
            return "";
         * */
        return "txt";
    }

    private String composeNumberPart()
    {
        String s = ApplicationSettings.getInstance().getProperty(I.I(4152));
        if(I.I(4192).equals(s) || I.I(4195).equals(s))
        {
            String s1 = (new StringBuilder()).append("").append(_fileSequenceNumber).toString();
            String s2 = "";
            if(s1.length() > 3)
            {
                s2 = (new StringBuilder()).append(I.I(4880)).append(s1).toString();
            } else
            {
                String s3 = "";
                for(int i = 0; i < 3 - s1.length(); i++)
                    s3 = (new StringBuilder()).append(s3).append(I.I(548)).toString();

                s2 = (new StringBuilder()).append(I.I(4880)).append(s3).append(s1).toString();
            }
            _fileSequenceNumber++;
            return s2;
        } else
        {
            return "";
        }
    }

    public static final String getResulFileName(String s)
    {
        if(Env.getEnv().isTraceWindowParsing())
            return I.I(4844);
        //FileNamePanel filenamepanel = (FileNamePanel)Env.getEnv().get(I.I(4653));
        String s1 = ApplicationSettings.getInstance().getProperty(I.I(4612));
        if(I.I(4676).equals(s1))
        return "temp";//return filenamepanel.getUserSpecifiedFileName();
        if(I.I(4681).equals(s1))
            return "temp";//return composeName(s, filenamepanel.getLabelExtenstion());
        if(I.I(1339).equals(s1))
            return "temp";//return composeName(I.I(4866), filenamepanel.getDateTimeExtenstion());
        else
            return "";
    }

    private String composeFileNamePart(String s)
    {
        String s1 = ApplicationSettings.getInstance().getProperty(I.I(4612));
        //FileNamePanel filenamepanel = (FileNamePanel)Env.getEnv().get(I.I(4653));
        if(I.I(4676).equals(s1))
            return "temp";//return filenamepanel.getUserSpecifiedFileName();
        if(I.I(4681).equals(s1))
            return s;
        if(I.I(1339).equals(s1))
        {
            if(_dateTimeName != null)
            {
                return _dateTimeName;
            } else
            {
                SimpleDateFormat simpledateformat = new SimpleDateFormat(I.I(4685));
                _dateTimeName = simpledateformat.format(new Date());
                return _dateTimeName;
            }
        } else
        {
            return "";
        }
    }

    private static String composeName(String s, String s1)
    {
        if(s != null)
        {
            String s2 = s;
            if(s.indexOf(I.I(467)) != -1)
                s2 = returnFileName(s);
            return (new StringBuilder()).append(s2).append(I.I(467)).append(s1).toString();
        } else
        {
            return I.I(4629);
        }
    }

    private static String returnFileName(String s)
    {
        int i = s.lastIndexOf(I.I(467));
        String s1 = s.substring(0, i);
        String s2 = s.substring(i + 1);
        boolean flag = true;
        try
        {
            Integer.parseInt(s2);
        }
        catch(NumberFormatException numberformatexception)
        {
            flag = false;
        }
        if(flag)
            return s;
        else
            return s1;
    }

    private String getType()
    {
        return ApplicationSettings.getInstance().getProperty(I.I(4612));
    }

    private String _dateTimeName;
    private static final int AMOUNT_VALUE_LENGTH = 3;
    private long _fileSequenceNumber;
}
